var examCode = "1";
var subjectsValue2 = "1";
var pageNum = 1;
var wordNum = 1;
var pageSize = 15;
var paperSearchValue = "";//试卷
var wordSearchValue = "";//句子
var numSearchValue = "";//词频
var wordsList = [];
var searchStatus = "0";//试卷搜索
var minDate = "2000";
var lastMinDate = "2000";
var maxDate = "2019";
var lastMaxDate = "2019";
var provinceCode = "";
var choseUrl= "";
var choseWord = "";
var choseObj = {
    "pageNum" : 1,
    "pageSize" : 15,
    "maxYear" : "2019",
    "minYear" : "2000",
    "province" : "",
    "exam" : "1",
    "minCp" : ""
}
var exportStatus = false;
$(function () {
    getAjax("/sjgl/user/getUserInfo", function(data){
        if(data){
            var name = data.name;
            var html = '<a href="javascript:void(0);">欢迎你，<span>'+ name +'</span> </a>&nbsp;&nbsp;<a href="javascript:void(0)" id="loginOut">退出 </a>';
            $(".login").html(html);
            $("#loginOut").unbind().on("click", function () {
                loginOut();
            });
            $(".register").hide();
        }else{
            var html = '<a class="btn-login" target="_self" href="login.html">登录</a>';
            $(".login").html(html);
            $(".register").hide();
        }
    }, function(e){
        var html = '<a class="btn-login" target="_self" href="login.html">登录</a>';
        $(".login").html(html);
        $(".register").hide();
    });

    getAjax("/sjgl/sentence/getDict?type=exam", function(data){
        var html1 = '';
        var html2 = '';
        for(var i=0; i < data.length; i++){
            var name = data[i].name;
            var code = data[i].code;
            var sel = "";
            if(i == 0){
                sel = "selected";
            }
            html1 += '<li data-code="'+code+'" id="SNAD'+(i+1)+'" class="'+sel+'" onclick="CrossDb(this)"><i></i><a href="javascript:void(0);">'+name+'</a></li>';
            html2 += '<li data-code="'+code+'" id="zsy'+(i+1)+'" class="'+sel+'" onclick="SingleDb(this)"><i></i><a href="javascript:void(0);">'+name+'</a></li>';
        }
        $("#wx_ul").html(html1);
        $(".zsy").html(html2);
    }, function(e){
        console.log(e);
    });

    getAjax("/sjgl/sentence/getDict?type=province", function(data){
       for(var i = 0; i < data.length; i++){
           var code = data[i].code;
           var name = data[i].name;
            var html = '<li val="'+(i+1)+'"><a data-code="'+code+'" href="javascript:void(0);">'+name+'</a></li>';
            $('#DBFieldList1').append(html);
        }
        $('#DBFieldList1').css("height", "200px");
        $('#DBFieldList1').css("overflow-x", "hidden");
        $('#DBFieldList1').css("overflow-y", "auto");
        init();
    }, function(e){
        console.log(e);
        init();
    });
    addCssChange();
});
/**
 * 初始化方法
 */
function init(){
    searchTab();

    sort(".sort", "cur", function(e){

    });
    sort(".sort1", "cur",function(data){
        if(data != null){
            var code = data.code == null ? "" : data.code;
            $("#DBFieldBox1").find("span").data("code", code);
        }
    });

    $(".option-list").find("li>i").click(function () {
        $(this).parent().toggleClass("selected")
    });

    $(".search-btn").click(function () {
        var type = $(".search-btn").data("type");
        if(type == "2"){
            if($("#DBFieldBox1").find("span").data("code") == null || $("#DBFieldBox1").find("span").data("code") == ""){
                alert("请选择省份");
                return;
            }
            //上传
            $("#upteainput").val("");
            $("#upteainput").click();
        }else{
            $("#pageList").hide();
            $(".pdfobject-com").hide();
            var inputValue = $(".search-input").val();
            var _inputDefaultVal = $(".search-input").attr("placeholder");
            if (!!inputValue == false || inputValue == _inputDefaultVal) {
                if($("#DBFieldBox .sort-default span").text() == "句子"){
                    alert("请输入检索内容！");
                    return false
                }
            }
            setInitStatus();
            var selectedValue = $("#DBFieldBox .sort-default span").text();
            changeSearchType(selectedValue,inputValue);
        }

    });

    $(".search-input").bind("keydown", function (e) {
        if (e.which == 13) {
            e.preventDefault();
            $(".search-btn").click();
            return false
        }
    });

    $(".pdfobject-com").on('click',function(){
        $(".paper-index-list").html("");
        $(".pdfobject-com").hide();

        if(searchStatus == "0"){
            //返回试卷
            getPaperList(pageNum,pageSize,paperSearchValue);
        }else{
            getWordList(wordNum, pageSize, wordSearchValue);
        }
    });
    upload();
    getPaperList(pageNum,pageSize,paperSearchValue);
    laydate.render({
        elem: '#test7'
        ,type: 'year'
        ,max: '2030'
        ,btns: ['confirm']
        ,value: '2000 - 2019'
        ,trigger: 'click'
        ,theme: '#2c72ec'
        ,range: true
        ,done: function(value, date, endDate){
            minDate = date.year;
            maxDate = endDate.year;
        }
    });

    $("#exportBtn").on("click",function(){
        var provinceC = $("#DBFieldBox1").find("span").data("code");
        var cpNum = choseObj.minCp;
        var url = "/sjgl/word/export?exam="+examCode+"&maxYear="+maxDate+"&minYear="+minDate+"&province="+provinceC+"&minCp="+cpNum;
        window.open(url);
    });
}

function upload(){
    $("#upteainput").change(function () {
        if( $("#upteainput").val() == ""){
            return;
        }
        $val = $("#upteainput").val();
        if ($val != '') { //要上传的文件名不为空
            // $data = new FormData($("#upform")[0]); //创建一个formdata对象
            var form = document.getElementById('upform');
            var formData = new FormData(form);

            var files = document.getElementById("upteainput").files;
            var str = "";
            for(var i = 0; i < files.length; i++){
                str += files[i].name +　";";
            }
            str = str.substring(0, str.length - 1);
            $("#txt_SearchText").val(str);
            $("#hiddendiv").show();
            var provinceCode = $("#DBFieldBox1").find("span").data("code");
            $.ajax({
                url: "http://" + window.location.host + "/sjgl/word/upFile?subjects=英语&exam=" + subjectsValue2 + "&province=" + provinceCode,
                type: "POST",
                data: formData,
                processData:false,
                contentType:false,
                // dataType: "script",
                error: function (a,b,c) {
                    console.log(a);
                    $("#hiddendiv").hide();
                },
                success: function (data, status) {
                    if(data.indexOf("上传成功") >= 0){
                        $("#hiddendiv").hide()
                        alert(data);
                        // window.location.reload();
                        //上传成功后显示最新的是试卷信息
                        setInitStatus();
                        getPaperList(pageNum,pageSize,paperSearchValue);
                    }else{
                        $("#hiddendiv").hide()
                        alert(data);
                    }

                }
            });
        }
    });
}

function searchTab(){
    $(".search-tab").find("li").click(function () {
        _index = $(this).parent().find("li").index(this);
        $(this).parents(".wrapper").removeClass("section1 section2 section3").addClass("section" + (
            _index + 1));
        $(this).addClass("on").siblings().removeClass("on");
        $(".banner").find("li").eq(_index).fadeIn(1000).siblings().fadeOut(1000);
        // $(".input-box").removeClass("fullinput");
        if ($(this).attr("val") == "doc") {
            $("#txt_SearchText").attr("placeholder", "请输入...");
            $(".reopt").show();
            $(".search-btn").data("type", "1");
            $(".date-range").show();
            // if($(".sort").find("span").text().indexOf("词频") >= 0){
            //     $(".search-input").hide();
            //     $(".input-box").css("width", (765-437) + "px");
            // }else{
            //     $(".search-input").show();
            //     $(".input-box").css("width", "765px");
            // }
        } else {
            if ($(this).attr("val") == "ref") {
                // $(".search-input").show();
                // $(".input-box").css("width", "765px");
                $(".date-range").hide();
                $("#txt_SearchText").attr("placeholder", "点击上传按钮上传");
                $(".reopt").hide();
                $(".search-btn").data("type", "2");
            } else {
                $("#txt_SearchText").attr("placeholder", "")
            }
        }
    });
}

function sort(sortSelector, curClass,callbackFun) {
    $(sortSelector).mouseenter(function () {
        $selectList = $(this).find("ul");
        $selectList.show();
        $selectList.find("a").click(function () {
            $selectList.siblings().find("span").html($(this).text());
            $(this).parent().addClass(curClass).siblings().removeClass(curClass);
            $selectList.hide();
            callbackFun($(this).data());
        })
    }).mouseleave(function () {
        $selectList.hide()
    })
}
/*************************************************************************************************************************/
/**
 *查询试卷
 * @param pageNum
 * @param pageSize
 * @param value
 */
function getPaperList(pageNum,pageSize,value){
    changeContentCss();
    $.ajax({
        url: "/sjgl/paper/getList?name=" + value + "&pageNum=" + pageNum + "&pageSize=" + pageSize + "&subjects=英语"
            +"&maxYear=" + maxDate + "&minYear=" + minDate + "&province=" + provinceCode + "&exam=" + examCode,
        type: "GET",
        dataType: "json",
        error: function (e) {
            console.log(e);
        },
        success: function (data) {
            if(!data.content || data.content.length == 0){
                nodataShow();
            }else{
                var totalElements = data.totalElements;
                var totalPages = data.totalPages;
                fillPaperContent(data);
                fillPageList(pageNum,pageSize,totalPages,totalElements);
            }

        }
    });
}

function fillPaperContent(data){
    var html = '';
    for(var i = 0; i < data.content.length; i++){
        var title = data.content[i].name;
        var paperName = title;

        var datapdf = data.content[i].pdfPath;
        html += '<li class="border pdfclick">';
        html += '<div class="new-mark"><em>卷</em></div>';
        html += '<div class="iblock p15 new-cont">';
        html += '<div><a class="paper-pdf" data-pdf="'+datapdf+'" href="javascript:void(0)" onclick="openLoginUI(this)" title="'+title+'">'+paperName+'</a></div>';

        if(data.content[i].createTime != null){
            var time = (data.content[i].createTime.indexOf(" ") >= 0) ? data.content[i].createTime.substring(0,data.content[i].createTime.indexOf(" ")) : data.content[i].createTime;
            var date = "上传时间：" + time;
            html += '<div><span>'+date+'</span></div>';
        }
        html += '</div></li>';
    }
    $(".paper-index-list").html(html);
    var w = $(".unit-box1").width();
    var liW = (w/3)  - 36;
    $(".paper-new li").css("width", liW + "px");//修改试卷显示宽度
    $(".p15").css("width", liW - 83 + "px");//修改试卷显示宽度
    $(".p15").css("height", "50px");
}

function  openLoginUI (t) {
    var url = $(t).data("pdf");
    if(url == ""){
        alert("此试卷无对应pdf");
        return;
    }
    $(".paper-index-list").html("");
    $("#pageList").hide();
    $(".pdfobject-com").show();

    url = "http://123.160.246.203:8287" + url;//http://localhost:55000/1.pdf
    // url = "http://123.160.246.203:8281/resource/1.pdf";
    PDFObject.embed(url, "#pdfArea");
    changeContentCss();
}
/*************************************************************************************************************************/
/**
 * 查询句子
 * @param value
 */

function getWordsNum(value){
    var h = $(window).height();
    var h1 = $(".header").height();
    var h2 = $(".searchmain").height();
    var productContentH = h - h1 - h2 - 40 - 30;

    if(productContentH<623){
        productContentH = 623;
    }
    $(".product-content").css("height", productContentH + "px");//修改下方高度
    $("#pdfArea").css("height", productContentH - 100 + "px");//修改下方高度

    $.ajax({
        // url: "/sjgl/sentence/getCount?word=" + value,
        url: "/sjgl/sentence/getPaperByWord?pageNum=0&pageSize=0&word=" + value + "&maxYear=" +
                maxDate + "&minYear=" + minDate + "&province=" + provinceCode + "&exam=" + examCode,
        // url: "/sjgl/sentence/getCp?pageNum=" +pageNum+ "&pageSize="+pageSize+"&maxYear=" + maxDate
        //     + "&minYear=" + minDate + "&province=" + provinceCode + "&exam=" + examCode+"&word=" + value,
        type: "GET",
        dataType: "json",
        error: function (e) {
            console.log(e);
        },
        success: function (data) {
            if(!data.content || data.content.length == 0){
                nodataShow();
            }else{
                fillWordsDetails(data);
            }

        }
    });
    // fillWordsDetails();
}

function fillWordsDetails(data){
    var html = '<table style="width: 100%;height: 100%;">'
        + '<tbody><tr>'
        + '<td style="width: 20%;height: 100%;font-size: 60px;text-align: center;color: #2323d4;height: 50px;line-height: 50px;">'+wordSearchValue+' </td>'
        + '<td style="width: 50%;text-align: center;">'
        + '<ul id="paperUl" style="width: 100%;padding: 0px;overflow-y: auto;overflow-x: hidden;">';
    for(var i=0; i<data.content.length;i++){
        var name = data.content[i].name;
        html += '<li class="paperUlLi" style="width:100%;float: none;height: auto;font-size: 16px;cursor: pointer">'+name+'</li>';
    }

    html += '</ul></td>'
        + '<td style="width: 30%;text-align: center;font-size: 22px;">共出现'
        + '<span style="color: #de1d1d;font-size: 40px;">'+ data.content.length + '</span>次</td>'
        + '</tr></tbody></table>'
        + '<div id="wordsNumBtn" style="float: right;margin-bottom: 10px;margin-right: 55px;cursor: pointer;">查看详情</div>';
    $(".paper-index-list").html(html);
    var h = $("#pdfArea").height();
    // $("#paperUl").css("height", h+"px");
    $("#wordsNumBtn").on("click",function () {
        getWordList(wordNum,pageSize,wordSearchValue);
    })
}

function getWordList(wordNum,pageSize,value){
    changeContentCss();
    $.ajax({
        // url: "/sjgl/sentence/getList?sentence=" + value + "&pageNum=" + wordNum + "&pageSize=" + pageSize,
        url: "/sjgl/sentence/getList?sentence=" + value + "&pageNum=" + wordNum + "&pageSize=" + pageSize
        +"&maxYear=" + maxDate + "&minYear=" + minDate + "&province=" + provinceCode + "&exam=" + examCode,
        type: "GET",
        dataType: "json",
        error: function (e) {
            console.log(e);
        },
        success: function (data) {
            if(!data.content || data.content.length == 0){
                nodataShow();
            }else{
                wordsList = data.content;
                var totalElements = data.totalElements;
                var totalPages = data.totalPages;
                fillWordContent(data);
                fillPageList(wordNum,pageSize,totalPages,totalElements);
            }

        }
    });
}

function fillWordContent(data){
    var html = '';
    for(var i = 0; i < data.content.length; i++){
        var title = data.content[i].sentence;
        var paperName = title;
        if(paperName.toString().length  > 50){
            paperName = paperName.toString().substring(0,50) + "...";
        }

        var paper_id = data.content[i].paper_id;
        html += '<li class="border pdfclick"><div class="new-mark"><em>句</em></div><div class="iblock p15 new-cont" style="font-size: 15px"><div>';
        html += '<a class="paper-pdf" href="javascript:void(0)" title="'+title+'">'+paperName+'</a>';
        html += '</div>';
        html += '<div style="float: right;line-height: 30px;height: 30px;margin-top: 10px;font-size: 10px;">';
        html += '<span class="wordBtn" onclick="showWords(this)" data-num="'+i+'">查看全句</span>&nbsp;<span onclick="openPaper(this)" data-paper="'+paper_id+'" class="wordBtn">查看试卷</span></div></div></li>';
    }
    $(".paper-index-list").html(html);
    var w = $(".unit-box1").width();
    var liW = (w/3)  - 36;
    $(".paper-new li").css("width", liW + "px");//修改试卷显示宽度
    $(".p15").css("width", liW - 83 + "px");//修改试卷显示宽度
    $(".p15").css("height", "50px");

}

function showWords(t) {
    var num = $(t).data("num");
    if(num == null || num === ""){
        return;
    }
    var words = wordsList[parseInt(num)].sentence == null ? "无内容" : wordsList[parseInt(num)].sentence;
    var witdh = $("#pdfArea").width();
    var witdh1 = parseInt($("#pdfArea").css("padding-left"));
    var witdh2 = parseInt($("#pdfArea").css("padding-right"));
    var w = witdh - witdh1 - witdh2;

    var html = '<div style="width: 77px;height:40px;z-index: 2016;margin-top: -23px;margin-left: -25px;">';
    html += '<a class="pdfobject-com-a" href="javascript:void(0);">返回列表</a></div>';
    html += '<div style="font-size: 16px;width: '+w+'px"><p >' + words + '<p></div>'

    $(".paper-index-list").html(html);
    $("#pageList").hide();
    $(".pdfobject-com").hide();
    $(".pdfobject-com-a").on('click',function(){
        $(".paper-index-list").html("");
        $(".pdfobject-com").hide();
        getWordList(wordNum, pageSize, wordSearchValue);
    })
}

function  openPaper(t) {
    var id = $(t).data("paper");
    if(id==null || id == ""){
        return;
    }
    $.ajax({
        url: "/sjgl/paper/getOne?paperId=" + id,
        type: "GET",
        dataType: "json",
        error: function (e) {
            console.log(e);
        },
        success: function (data) {
            if(!data.pdfPath){
                nodataShow();
            }else{
                $(".paper-index-list").html("");
                $("#pageList").hide();
                $(".pdfobject-com").show();

                url = "http://123.160.246.203:8287" + data.pdfPath;//http://localhost:55000/1.pdf
                // url = "http://123.160.246.203:8281/resource/1.pdf";
                PDFObject.embed(url, "#pdfArea");
                changeContentCss();
            }

        }
    });
}
/*************************************************************************************************************************/

/**
 * 查询词频
 * @param pageNum
 * @param pageSize
 * @param value
 */
function getNumList(pageNum,pageSize,value){
    provinceCode = $("#DBFieldBox1").find("span").data("code");
    changeContentCss();
    choseObj = {
        "pageNum" : pageNum,
        "pageSize" : pageSize,
        "maxYear" : maxDate,
        "minYear" : minDate,
        "province" : provinceCode,
        "exam" : examCode,
        "minCp" : value,
    };
    $.ajax({
        url: "/sjgl/sentence/getCp?pageNum=" +pageNum+ "&pageSize="+pageSize+"&maxYear=" + maxDate
            + "&minYear=" + minDate + "&province=" + provinceCode + "&exam=" + examCode + "&minCp=" + value,
        type: "GET",
        dataType: "json",
        error: function (e) {
            console.log(e);
        },
        success: function (data) {
            if(!data.content || data.content.length == 0){
                nodataShow();
            }else{
                exportStatus = true;
                var totalElements = data.totalElements;
                var totalPages = data.totalPages;
                fillNumListContent(data);
                fillPageList(pageNum,pageSize,totalPages,totalElements);
                $("#exportBtn").show();
            }

        }
    });
}

function fillNumListContent(data){
    var html = '';
    var w = $(".unit-box1").width();
    var textNum = 15;
    var mc = parseInt(pageNum - 1)*pageSize
    if(w > 1700){
        textNum = 20;
    }else{

    }
    for(var i = 0; i < data.content.length; i++){
        var words = data.content[i].word;
        var title = data.content[i].word;

        if(words.toString().length > textNum){
            words = words.toString().substring(0,textNum) + "...";
        }
        var paperName = title;
        var wordsNum = data.content[i].count;
        var code = data.content[i].id;
        var mcNum = mc + i + 1;
        html += '<li class="border pdfclick">' +
                '<div class="new-mark"><em style="width: 30px;height: 30px;line-height: 30px;">' + mcNum + '</em></div>' +
                    '<div class="iblock p15 new-cont">' +
                        '<div style="overflow: hidden;">' +
                            '<span style="white-space: nowrap;">关键词：</span><span class="numSpan" title="'+title+'">'+words+'</span>' +
                        '</div>' +
                        '<div style="overflow: hidden;">' +
                            '<span style="white-space: nowrap;">频次：</span><span class="numSpan">'+wordsNum+'</span>' +
                        '</div>' +
                        '<div style="float: right;line-height: 30px;height: 30px;margin-top: -15px;font-size: 10px;">' +
                            '<span class="wordBtn" onclick="showNumDetail(this)" data-code="'+code+'">查看详情</span>' +
                        '</div>' +
                    '</div>' +
                '</li>';
    }

    $(".paper-index-list").html(html);
    var liW = (w/3)  - 36;
    $(".paper-new li").css("width", liW + "px");//修改试卷显示宽度
    $(".p15").css("width", liW - 83 + "px");//修改试卷显示宽度
    $(".p15").css("height", "50px");
    lastMinDate = minDate;
    lastMaxDate = maxDate;
}

function showNumDetail(t){
    exportStatus = false;
    $("#exportBtn").hide();
    var code = $(t).data("code");
    // choseUrl = "wordId=" + code;
    changeContentCss();
    $.ajax({
        url: "/sjgl/sentence/getPaperByWord?pageNum=0&pageSize=0&wordId=" + code + "&maxYear=" + maxDate + "&minYear=" + minDate + "&province=" + provinceCode + "&exam=" + examCode,
        type: "GET",
        dataType: "json",
        error: function (e) {
            console.log(e);
        },
        success: function (data) {
            if(!data.content || data.content.length == 0){
                nodataShow();
            }else{
                $("#pageList").hide();
                fillDeatail(data);
            }

        }
    });
}

function fillDeatail(data){
    var html = '<div id="backToNum" style="position: fixed;right: 97px;width: 100px;margin-top: -21px;height: 35px;line-height: 35px;background: #6699FF;text-align: center;color: #fff;cursor: pointer;">返回列表</div>';
    var num = data.content.length;
    if(num <= 0){
        $(".paper-index-list").html("<p style='font-size: 18px'>无查询结果</p>");
        return;
    }
    var word = data.content[0].word;
    choseUrl = "maxYear=" + maxDate + "&minYear=" + minDate + "&province=" + provinceCode + "&exam=" + examCode;
    choseWord = word;
    html += '<div><p class="p_detail">关键词：</p><p class="p_import">'+word+'</p></br></div>';
    html += '<div><p class="p_detail">出现频次：</p><p class="p_import">'+num+'</p></br></div>';
    html += '<div><p class="p_detail">出现句子：</p><button style="cursor: pointer;width: 76px;height: 30px;line-height: 30px;text-align: center;background: #6699ff;border: 0px;color: #fff;font-weight: 800;" onclick="openPop()">点击显示</button></br></div>';
    html += '<div style="height: calc(100% - 68px);width: calc(100% - 33px);overflow-y: auto;overflow-x: hidden;"><p class="p_detail">出现试卷：</p>'
    for(var i = 0; i < data.content.length; i++){
        var year = data.content[i].year;
        var name = data.content[i].province;
        var fullName = data.content[i].name;
        var name1 = year + name;
        var name2 = fullName;//
        if(name2.indexOf(".doc")){
            name2 = name2.substring(0,name2.indexOf(".doc"));
        }
        var title = name2;//name1 + " 【 " + name2 + " 】 ";

        if(i != data.content.length - 1){
            title += '、';
        }
        html += '<p class="p_import">'+title+'</p>';
    }
    html += '</div>';
    $(".paper-index-list").html(html);
    $("#backToNum").on("click",function(){
        // choseObj = {
        //     "pageNum" : pageNum,
        //     "pageSize" : pageSize,
        //     "maxYear" : maxDate,
        //     "minYear" : minDate,
        //     "province" : provinceCode,
        //     "exam" : examCode,
        //     "minCp" : value,
        // }
        getNumList(choseObj.pageNum,choseObj.pageSize,choseObj.minCp);
    })
}

function fillNumPaperContent(data){
    var html = '';
    for(var i = 0; i < data.content.length; i++){
        var title = data.content[i].name;
        var paperName = title;

        var datapdf = data.content[i].pdf_path;
        html += '<li class="border pdfclick">';
        html += '<div class="new-mark"><em>卷</em></div>';
        html += '<div class="iblock p15 new-cont">';
        html += '<div><a class="paper-pdf" data-pdf="'+datapdf+'" href="javascript:void(0)" onclick="openPdf(this)" title="'+title+'">'+paperName+'</a></div>';
        html += '</div></li>';
    }
    $(".paper-index-list").html(html);
    var w = $(".unit-box1").width();
    var liW = (w/3)  - 36;
    $(".paper-new li").css("width", liW + "px");//修改试卷显示宽度
    $(".p15").css("width", liW - 83 + "px");//修改试卷显示宽度
    $(".p15").css("height", "50px");
}

function openPdf(t){
    var url = $(t).data("pdf");
    if(url == ""){
        alert("此试卷无对应pdf");
        return;
    }

    url = "http://123.160.246.203:8287" + url;//http://localhost:55000/1.pdf
    // url = "http://123.160.246.203:8281/resource/1.pdf";
    // PDFObject.embed(url, "#pdfArea");

    layer.open({
        type: 2,
        title: false,
        maxmin: false,
        shadeClose: true, // 点击遮罩关闭层
        area: ['1096px', '650px'],
        content: 'pdf.html?url=' + url,
        offset: 'auto',
        btnAlign: 'c',
        closeBtn: 0
    });
    // changeContentCss();
}

function openPop(){
    var tempValue = "&sentence=" + choseWord;
        layer.open({
        type: 2,
        title: false,
        maxmin: false,
        shadeClose: true, // 点击遮罩关闭层
        area: ['1096px', '80%'],
        content: 'popWin.html?' + choseUrl + tempValue ,
        // offset: 'auto',
        btnAlign: 'c',
        closeBtn: 0
    });
}
/************************************************通用************************************************************************/
function fillPageList(pageNo,numPerPage,totalPage,totalSize){
    $("#pageList").show();
    if(totalSize > 0){
        $("#page").paging({
            pageNo: pageNo,
            numPerPage:numPerPage,
            totalPage: totalPage,
            totalSize: totalSize,
            callback: function(num) {
                if(searchStatus == "0"){
                    pageNum = num;
                    getPaperList(pageNum,pageSize,paperSearchValue);
                }else if(searchStatus == "1"){
                    wordNum = num;
                    // getWordList(wordNum, pageSize, wordSearchValue);
                    getWordsNum(wordSearchValue);
                }else if(searchStatus == "2"){
                    pageNum = num;
                    getNumList(pageNum, pageSize, numSearchValue);
                }
            }
        });
    }else{
        $(".page_div").html("");
    }
}

function changeContentCss(){
    var h = $(window).height();
    var h1 = $(".header").height();
    var h2 = $(".searchmain").height();
    var productContentH = h - h1 - h2 - 40 - 30;

    if($(".pdfobject") && $(".pdfobject").length > 0){
        productContentH = 950;
    }else{
        if(productContentH<623){
            productContentH = 623;
        }
    }
    $(".product-content").css("height", productContentH + "px");//修改下方高度
    $("#pdfArea").css("height", productContentH - 100 + "px");//修改下方高度

}

/**
 * index.html 勾选
 * @param a
 * @constructor
 */
function CrossDb(a) {
    $("#txt_SearchText").attr("placeholder", "请输入...");
    var b = ".option-list .wx";
    if ($(a).is(".selected")) {
        $(b).find("li").not($(a)).removeClass("selected")
    }
    examCode = $(a).data("code");
}

/**
 * index.html 单选
 * @param d
 * @constructor
 */
function SingleDb(d) {
    var b = ".option-list .zsy";
    if ($(d).is(".selected")) {
        $(b).find("li").not($(d)).removeClass("selected")
    }
    subjectsValue2 = $(d).data("code");
}

function loginOut(){
    $.ajax({
        url: "/sjgl/user/logout",
        type: "GET",
        dataType: "json",
        error: function () {
            debugger;
        },
        success: function (data, status) { //如果调用php成功
            if(data){
                window.location = "login.html";
            }else{
                alert("账号密码错误");
            }
        }
    });
}

function getCookie(cookie_name) {
    var allcookies = document.cookie;
    //索引长度，开始索引的位置
    var cookie_pos = allcookies.indexOf(cookie_name);

    // 如果找到了索引，就代表cookie存在,否则不存在
    if (cookie_pos != -1) {
        // 把cookie_pos放在值的开始，只要给值加1即可
        //计算取cookie值得开始索引，加的1为“=”
        cookie_pos = cookie_pos + cookie_name.length + 1;
        //计算取cookie值得结束索引
        var cookie_end = allcookies.indexOf(";", cookie_pos);

        if (cookie_end == -1) {
            cookie_end = allcookies.length;

        }
        //得到想要的cookie的值
        var value = unescape(allcookies.substring(cookie_pos, cookie_end));
    }
    return value;
}

function setInitStatus(){
    pageNum = 1;
    wordNum = 1;
    pageSize = 15;
    paperSearchValue = "";//试卷
    wordSearchValue = "";//句子
    numSearchValue = "";//词频
    choseCp = "";//词频归零
}

function changeSearchType(selectedValue, inputValue){
    exportStatus =  false;
    provinceCode = $("#DBFieldBox1").find("span").data("code");
    if(selectedValue == "试卷"){
        $("#exportBtn").hide();
        paperSearchValue = inputValue;
        searchStatus = "0";
        getPaperList(pageNum,pageSize,paperSearchValue);
    }else if(selectedValue == "句子"){
        $("#exportBtn").hide();
        wordSearchValue = inputValue;
        searchStatus = "1";
        getWordsNum(wordSearchValue);
    }else if(selectedValue == "词频"){
        numSearchValue = inputValue;
        searchStatus = "2";
        if(numSearchValue != "" && isNaN(parseInt(numSearchValue))){
            alert("请输入数字");
            $(".search-input").focus();
            return;
        }else{
            getNumList(pageNum,pageSize,numSearchValue);
        }
    }
}

function getAjax(url, callbackFun, errorFun) {
    $.ajax({
        url: url,
        type: "GET",
        dataType: "json",
        error: function (e) {
            errorFun(e);
        },
        success: function (data) {
            callbackFun(data);
        }
    });
}
function addCssChange(){
    window.onresize=function(){
        var h = $(window).height();
        var h1 = $(".header").height();
        var h2 = $(".searchmain").height();
        var productContentH = h - h1 - h2 - 40 - 30;

        if($(".pdfobject") && $(".pdfobject").length > 0){
            productContentH = 950;
        }else{
            if(productContentH<623){
                productContentH = 623;
            }
        }


        $(".product-content").css("height", productContentH + "px");//修改下方高度
        $("#pdfArea").css("height", productContentH - 100 + "px");//修改下方高度
        var w = $(".unit-box1").width();
        var liW = (w/3)  - 36;
        if($(".paperUlLi").length <= 0){
            $(".paper-new li").css("width", liW + "px");//修改试卷显示宽度
        }
        $(".p15").css("width", liW - 83 + "px");//修改试卷显示宽度
    }
}

function nodataShow(){
    exportStatus = false;
    $("#exportBtn").hide();
    $(".paper-index-list").html("<p style='font-size: 18px'>无查询结果</p>");
    $("#pageList").hide();
    $(".pdfobject-com").hide();
}